#!/bin/sh
#
# This script is used to download, verify, and extract the
# pre-compiled development and runtime libraries needed for
# pcb.
#

# directory where all the files have been downloaded
gtk_win32_downloads=${HOME}/gtk_win32_downloads

# directory to extract everything (including headers) to.
# This must match ./build_pcb.
gtk_win32=${HOME}/gtk_win32
gd_win32=${HOME}/gd_win32

# directory to extract runtime files (excluding headers) to.
# This must match ./build_pcb.
gtk_win32_runtime=${HOME}/gtk_win32_runtime
gd_win32_runtime=${HOME}/gd_win32_runtime

####
#

## %dep-start%

#atk
#1.32.0
#2
https://download.gnome.org/binaries/win32/atk/1.32/atk-dev_1.32.0-2_win32.zip
https://download.gnome.org/binaries/win32/atk/1.32/atk_1.32.0-2_win32.zip
https://download.gnome.org/sources/atk/1.32/atk-1.32.0.tar.bz2

#cairo
#1.10.2
#2
https://download.gnome.org/binaries/win32/dependencies/cairo-dev_1.10.2-2_win32.zip
https://download.gnome.org/binaries/win32/dependencies/cairo_1.10.2-2_win32.zip

#expat
#2.1.0
#1
https://download.gnome.org/binaries/win32/dependencies/expat-dev_2.1.0-1_win32.zip
https://download.gnome.org/binaries/win32/dependencies/expat_2.1.0-1_win32.zip

#fontconfig
#2.8.0
#2
https://download.gnome.org/binaries/win32/dependencies/fontconfig-dev_2.8.0-2_win32.zip
https://download.gnome.org/binaries/win32/dependencies/fontconfig_2.8.0-2_win32.zip

#freetype
#2.4.10
#1
https://download.gnome.org/binaries/win32/dependencies/freetype-dev_2.4.10-1_win32.zip
https://download.gnome.org/binaries/win32/dependencies/freetype-dev_2.4.10-1_win32.zip

#gd
#unknown
#unknown

unknown

#gdk-pixbuf
#2.24.0
#1
https://download.gnome.org/binaries/win32/gdk-pixbuf/2.24/gdk-pixbuf-dev_2.24.0-1_win32.zip
https://download.gnome.org/binaries/win32/gdk-pixbuf/2.24/gdk-pixbuf_2.24.0-1_win32.zip
https://download.gnome.org/sources/gdk-pixbuf/2.24/gdk-pixbuf-2.24.0.tar.bz2

# gettext
#0.18.1
#2
https://download.gnome.org/binaries/win32/dependencies/gettext-runtime-dev_0.18.1.1-2_win32.zip
https://download.gnome.org/binaries/win32/dependencies/gettext-runtime_0.18.1.1-2_win32.zip
https://download.gnome.org/binaries/win32/dependencies/gettext-tools-dev_0.18.1.1-2_win32.zip
https://download.gnome.org/binaries/win32/dependencies/gettext-tools_0.18.1.1-2_win32.zip
https://download.gnome.org/binaries/win32/dependencies/gettext-0.18.1.1.tar.gz

#glib
#2.28.8
#1
https://download.gnome.org/binaries/win32/glib/2.28/glib-dev_2.28.8-1_win32.zip
https://download.gnome.org/binaries/win32/glib/2.28/glib_2.28.8-1_win32.zip
https://download.gnome.org/sources/glib/2.28/glib-2.28.8.tar.bz2

#gtk+
#2.24.10
#1
https://download.gnome.org/binaries/win32/gtk+/2.24/gtk+-dev_2.24.10-1_win32.zip
https://download.gnome.org/binaries/win32/gtk+/2.24/gtk+_2.24.10-1_win32.zip
https://download.gnome.org/sources/gtk+/2.28/gtk+-2.24.10.tar.bz2

#intltool
#0.40.4
#1
https://download.gnome.org/binaries/win32/intltool/0.40/intltool-dev_0.40.4-1_win32.zip
https://download.gnome.org/binaries/win32/intltool/0.40/intltool_0.40.4-1_win32.zip
https://download.gnome.org/sources/intltool/0.40/intltool-0.40.4.tar.bz2

#libpng
#1.4.12
#1
https://download.gnome.org/binaries/win32/dependencies/libpng-dev_1.4.12-1_win32.zip
https://download.gnome.org/binaries/win32/dependencies/libpng_1.4.12-1_win32.zip

#pango
#1.29.4
#1
https://download.gnome.org/binaries/win32/pango/1.29/pango-dev_1.29.4-1_win32.zip
https://download.gnome.org/binaries/win32/pango/1.29/pango_1.29.4-1_win32.zip
https://download.gnome.org/sources/pango/1.29/pango-1.29.4.tar.bz2

#pixman
#0.24.0
#1
https://download.gnome.org/binaries/win32/dependencies/pixman-dev_0.24.0-1_win32.zip
https://download.gnome.org/binaries/win32/dependencies/pixman_0.24.0-1_win32.zip

#pkg-config
#0.25
#1
https://download.gnome.org/binaries/win32/dependencies/pkg-config-dev_0.25-1_win32.zip
https://download.gnome.org/binaries/win32/dependencies/pkg-config_0.25-1_win32.zip
https://download.gnome.org/binaries/win32/dependencies/pkg-config-0.25.tar.gz

#zlib
#1.2.5
#2
https://download.gnome.org/binaries/win32/dependencies/zlib-dev_1.2.5-2_win32.zip
https://download.gnome.org/binaries/win32/dependencies/zlib_1.2.5-2_win32.zip

## %dep-end%

# clean out old directories
test ! -d ${gtk_win32} || rm -fr ${gtk_win32}
test ! -d ${gtk_win32_runtime} || rm -fr ${gtk_win32_runtime}

test ! -d ${gd_win32} || rm -fr ${gd_win32}
test ! -d ${gd_win32_runtime} || rm -fr ${gd_win32_runtime}

# make the new ones
mkdir -p ${gtk_win32}
mkdir -p ${gtk_win32_runtime}

mkdir -p ${gd_win32}
mkdir -p ${gd_win32_runtime}/bin

# extract the runtime files
cd ${gtk_win32_runtime}
for f in ${gtk_win32_downloads}/*.zip ; do
	fb=`basename "${f}"`
	case "$fb" in
		gd-*)
			echo "Skip gd"
			;;
		*dev*)
			echo "Skip developer file `basename ${fb}`"
			;;
		*src*)
			echo "Skip source file `basename ${fb}`"
			;;
		*)
			echo "Extract ${fb}"
			unzip -n -q "$f"
			;;
	esac
done

# extract the runtime+developer files
cd ${gtk_win32}
for f in ${gtk_win32_downloads}/*.zip ; do
	fb=`basename "${f}"`
	case "$fb" in
		gd-*)
			echo "Skip gd"
			;;
		*src*)
			echo "Skip source file `basename ${fb}`"
			;;
		*)
			echo "Extract ${fb}"
			unzip -n -q "$f"
			;;
	esac
done

chmod 755 ${gtk_win32}/bin/*
mv ${gtk_win32_runtime}/zlib*.dll ${gtk_win32_runtime}/bin
chmod 755 ${gtk_win32_runtime}/bin/*

cd ${HOME}


cd ${gd_win32}
unzip ${gtk_win32_downloads}/gd-*-win32.zip
cp */*.dll ${gd_win32_runtime}/bin
cat > ${gd_win32_runtime}/gd-license.txt << EOF
The GD library which provides png/gif/jpeg exporting
is covered by the following license:

EOF
cat ${gd_win32}/COPYING.TXT >> ${gd_win32_runtime}/gd-license.txt
chmod 755 ${gd_win32}/*/*
chmod 755 ${gd_win32_runtime}/*

cd ${HOME}

# extract licenses

cd
tmpd=/tmp/ext.$$
mkdir ${tmpd}

cd ${tmpd}


cat > ${gtk_win32_runtime}/LICENSE-lgpl << EOF
The following packages are covered by the
GNU Library General Public License (LGPL)

atk
cairo
glib
gtk+
libiconv
pango
proxy-libintl

----------------------------------------

EOF

cat > ${gtk_win32_runtime}/LICENSE-gpl2 << EOF
The following packages are covered by the GNU General Public License (GPL) v2.

freetype
pkg-config

----------------------------------------

EOF

cat > ${gtk_win32_runtime}/LICENSE-gpl3 << EOF
The following packages are covered by the GNU General Public License (GPL) v3.

gettext

----------------------------------------

EOF


# LGPL
#
# atk-1.22.0.tar.bz2
# atk-1.22.0.zip
# atk-dev-1.22.0.zip

bzcat ${gtk_win32_downloads}/atk-*.tar.bz2 | tar -xf -
cat atk-*/COPYING >> ${gtk_win32_runtime}/LICENSE-lgpl
rm -fr atk-*

# dual LGPL and MPL (Mozilla public license)
#
#cairo-1.6.4.tar.gz
#cairo-1.6.4.zip
#cairo-dev-1.6.4.zip

# no copyright assigned and placed in public domain
#
# dirent.zip

# sort of BSD with advertising like
#expat-2.0.0.zip
echo "expat is covered by the following copyright and license" > ${gtk_win32_runtime}/LICENSE-expat
cat ${gtk_win32_downloads}/COPYING-expat >> ${gtk_win32_runtime}/LICENSE-expat


#fontconfig-2.4.2-tml-20071015.diff
#fontconfig-2.4.2-tml-20071015.zip
#fontconfig-2.4.2.tar.gz
#fontconfig-dev-2.4.2-tml-20071015.zip
tar -zxvf ${gtk_win32_downloads}/fontconfig-*.tar.gz
echo "fontconfig is covered by the following license" > ${gtk_win32_runtime}/LICENSE-fontconfig
cat fontconfig*/COPYING >> ${gtk_win32_runtime}/LICENSE-fontconfig
rm -fr fontconfig-*

#
# Dual, "you choose" license.  We pick GPL v2.
#freetype-2.3.4.tar.bz2
#freetype-2.3.4.zip
#freetype-dev-2.3.4.zip
#bzcat  ${gtk_win32_downloads}/freetype-2.3.4.tar.bz2  | tar -xvf - mv freetype-*/*/LICENSE.TXT ${gtk_win32_runtime}/LICENSE-freetype
#rm -fr freetype-*


# GPL v3
#
#gettext-0.17.tar.gz
#gettext-runtime-0.17.zip
#gettext-runtime-dev-0.17.zip
#gettext-tools-0.17.zip
tar -zxvf ${gtk_win32_downloads}/gettext-*.tar.gz
cat gettext-*/COPYING >> ${gtk_win32_runtime}/LICENSE-gpl3
rm -fr gettext-*


# LGPL
#glib-2.16.5.tar.bz2
#glib-2.16.5.zip
#glib-dev-2.16.5.zip

# LGPL
#
#gtk+-2.12.11.tar.bz2
#gtk+-2.12.11.zip
#gtk+-dev-2.12.11.zip


# jpeg license
#
#jpeg-6b-4-bin.zip
#jpeg-6b-4-dep.zip
#jpeg-6b-4-lib.zip
#jpegsrc.v6b.tar.gz

#unzip ${gtk_win32_downloads}/jpeg-*-src.zip
tar -zxvf ${gtk_win32_downloads}/jpegsrc.v6b.tar.gz
echo "libjpeg is covered by the following license:" > ${gtk_win32_runtime}/LICENSE-jpeg
cat jpeg-6b/README >> ${gtk_win32_runtime}/LICENSE-jpeg
rm -fr jpeg-6b

# LGPL
#
#libiconv-1.9.1.bin.woe32.zip
#libiconv-1.9.1.tar.gz

#libpng-1.2.9.tar.gz
#libpng-dev-1.2.9.zip
#libpng-1.2.9.zip
mkdir tmppng
cd tmppng
unzip ${gtk_win32_downloads}/libpng-dev-*.zip
ls
ls include

echo "libpng is covered by the following copyright and license" > ${gtk_win32_runtime}/LICENSE-png
awk '/COPYRIGHT/,/^[ \t]*$/ {print}' include/png.h >> ${gtk_win32_runtime}/LICENSE-png
cd ..
rm -fr tmppng

# LGPL
#
#pango-1.20.5.tar.bz2
#pango-1.20.5.zip
#pango-dev-1.20.5.zip


# GPL
#
#pkg-config-0.23.tar.gz
#pkg-config-0.23-2.zip
tar -zxvf ${gtk_win32_downloads}/pkg-config-*.tar.gz
cat pkg-config-*/COPYING >> ${gtk_win32_runtime}/LICENSE-gpl2
rm -fr pkg-config-*

# LGPL
#
# proxy-libintl-20080728.zip

# BSD-like with advertising clause
#
#tiff-3.8.2.tar.gz
#libtiff-3.8.2.zip
#libtiff-dev-3.8.2.zip
tar -zxvf ${gtk_win32_downloads}/tiff-*.tar.gz
echo "libtiff is covered by the following license:" > ${gtk_win32_runtime}/LICENSE-tiff
cat tiff-*/COPYRIGHT >> ${gtk_win32_runtime}/LICENSE-tiff
rm -fr tiff-*

# Not needed anymore
#xpm-nox-4.0.3-20020617.zip
#xpm-nox-dev-4.0.3-20020112.zip
#tar -zxvf ${gtk_win32_downloads}/xpm-*.tar.gz
#echo "The xpm library is covered by the following license and copyright:" > ${gtk_win32_runtime}/LICENSE-xpm
#cat xpm-*/COPYRIGHT >> ${gtk_win32_runtime}/LICENSE-xpm
#rm -fr xpm-*

#zlib123-dll.zip
# the license had to be found on the zlib web site
echo "zlib is covered by the following license and copyright" > ${gtk_win32_runtime}/LICENSE-zlib
cat ${gtk_win32_downloads}/zlib_license.txt >> ${gtk_win32_runtime}/LICENSE-zlib
